python protocol
Why
interfaceは表面上(signiture?)の整合性を見るだけなので、下部、内部の規約も必要(runtime レベルでは??)
protocolは(実際の ie: メソッド適用) 要件を満たしてるかを見る??(golang の interfaceはprotocol?) What
When used on object types for which they do not apply, they will raise a Python exception.
適用できないものに使うと例外あげます。
解説されてるもの
Python では、特定の性質を持つオブジェクトが実装すべき一連のメソッドのことをプロトコルと呼びます
So any object, regardless of it’s class/type, can conform to a certain interface just by implementing the expected behavior (methods). These informal interfaces are termed as protocols.
So we can see that protocols are like informal interfaces
QA
Q: 検索してもうまく情報が集まらない、informalな用語だから?
MISC
file
read
iterator
next?
container
__len__, __contains__,